////////////////////////////////////////////////////////////////////////////////
//
//	This file is part of Woozox, see <http://code.google.com/p/woozox/>.
//
//	Copyright 2008-2009 Florian David
//
//	Woozoo is free software: you can redistribute it and/or modify
//	it under the terms of the GNU Lesser General Public License as 
//	published by the Free Software Foundation, either version 3 of 
//	the License, or (at your option) any later version.
//
//	Woozoo is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU Lesser General Public 
//	License along with Woozoo. If not, see <http://www.gnu.org/licenses/>.
//
////////////////////////////////////////////////////////////////////////////////
package org.woozoo.xhtml.core.base.selector
{
	import org.woozoo.xhtml.core.base.Element;
	
	/**
	 * @private
	 * 
	 * TODO : Do study case
	 * */
	internal final class SelectorOperatorLang extends AbstractSelectorOperator
	{
		/**
		 * In this HTML example, only the BODY matches [lang|=fr] (because it has a LANG attribute) 
		 * but both the BODY and the P match :lang(fr) (because both are in French). 
		 * The P does not match the [lang|=fr] because it does not have a LANG attribute.
		 *	<body lang=fr>
		 *	  <p>Je suis français.</p>
		 *	</body>
		 * */
		override protected function _operateElements() : Array {
			var split : Array = str.split(':lang('); 
			var lang : String = split[0];
			debugFunction('we interpret lang '+ str+' :: lang=['+lang+']');

			var res : Array = [];
			for (var i : int = 0; i < elementsLength; i++) {
				var element : Element = getElementAt(i);
				if (element.hasValueInAttributeHyphenSeparated('lang', lang)) {
					res.concat(element, element.childrenAndSoOn);
				}
			}
			return res;
		}
	}
}